//
//  CWHomeTableVewCellFootView.swift
//  SinaBlog
//
//  Created by ChenWei on 15/11/30.
//  Copyright © 2015年 cw. All rights reserved.
//

import UIKit

// MARK: - CWHomeTableVewCellFootView:底部评论视图
class CWHomeTableVewCellFootView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        // 1.初始化UI
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 内部方法
    private func setupUI() {
        
        // 1.添加子控件
        addSubview(retweetBtn)
        addSubview(commentBtn)
        addSubview(likeBtn)
        addSubview(separateView1)
        addSubview(separateView2)
        
        // 2.布局子控件
        // 2.1布局转发
        retweetBtn.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.left.equalTo(self)
            make.height.equalTo(self)
        }
        // 2.2布局评论
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.left.equalTo(retweetBtn.snp_right)
            make.height.equalTo(self)
            make.width.equalTo(retweetBtn)
        }
        
        // 2.3布局赞
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.left.equalTo(commentBtn.snp_right)
            make.right.equalTo(self)
            make.height.equalTo(self)
            make.width.equalTo(retweetBtn)
        }
        // 2.4布局分隔线1
        separateView1.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(10)
            make.left.equalTo(retweetBtn.snp_right)
            make.width.equalTo(0.5)
            make.bottom.equalTo(self).offset(-10)
        }
        // 2.4布局分隔线2
        separateView2.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(10)
            make.left.equalTo(commentBtn.snp_right)
            make.width.equalTo(0.5)
            make.bottom.equalTo(self).offset(-10)
        }
    }
    
    // MARK: - 懒加载
    /// 1.转发
    private lazy var retweetBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "timeline_icon_retweet"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        
        btn.setTitle("转发", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -5)
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5)
        
        return btn
    }()
    /// 2.评论
    private lazy var commentBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "timeline_icon_comment"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        
        btn.setTitle("评论", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -5)
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5)
        
        return btn
    }()
    /// 3.赞
    private lazy var likeBtn: UIButton = {
        let btn = UIButton(title: "赞", iamgeName: "timeline_icon_unlike")
        btn.setImage(UIImage(named: "timeline_icon_like"), forState: UIControlState.Selected)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        
        btn.setTitle("赞", forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -5)
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5)
        
        return btn
    }()
    /// 4.分隔线1
    private lazy var separateView1: UIView = self.createSeparateLine()
    private lazy var separateView2: UIView = self.createSeparateLine()
    private func createSeparateLine() -> UIView {
        let v = UIView()
        v.backgroundColor = UIColor.darkGrayColor()
        return v
    }
}
